// scan.js
var util = require('../../utils/util.js')
var app = getApp();
var md5 = require('../md5.js');
// 移动动画
let animation = wx.createAnimation({});
// 提示音
let innerAudioContext = wx.createInnerAudioContext()
//innerAudioContext.src = '/images/beep.mp3'

Page({
  data: {
    
  },
  onLoad: function () {
    
  },
  onShow(){
    this.donghua()
  },
  onPullDownRefresh: function(){
    wx.stopPullDownRefresh({
      complete: (res) => {},
    });
  },
  toEmailSignIn: function () {
    wx.reLaunch({
      url: '../signInbyEmail/signIn'
    })
  },
  toPhoneSignIn: function () {
    wx.reLaunch({
      url: '../signInbyPhone/signIn'
    })
  },
  donghua(){
    var that = this;
	// 控制向上还是向下移动
    let m = true
	
    setInterval(function () {
      if (m) {
        animation.translateY(200).step({ duration: 3000 })
        m = !m;
      } else {
        animation.translateY(10).step({ duration: 3000 })
        m = !m;
      }

      that.setData({
        animation: animation.export()
      })
    }.bind(this), 3000)
  },
  scancode(e){
    // 提示音
    //innerAudioContext.play()
    // 校验扫描结果，并处理
    let res = e.detail.result
    console.log('res='+res)
    var scanMsg = res
    var hceMsg=''
    //nfc获取信息
    wx.getHCEState({
      success(res) {
        console.log('hcestate='+res.errCode)
        var resState = res.errCode
        if (resState=='0'){
          wx.startHCE({
            aid_list: ['F222222222'],
            success(res) {
              console.log('hceMsg=' + res.errMsg)
              hceMsg = res.errMsg
            }
          })
        }
      }
    })
    if (!(scanMsg == '' || scanMsg == null) || !(hceMsg == '' || hceMsg == null)){
      var verificationcode=''
      if (!(scanMsg == '' || scanMsg == null)){
        verificationcode = scanMsg
      }else{
        verificationcode = hceMsg
      }
      wx.navigateTo({
        url: '../phoneVerification/phoneVerification?verificationcode=' + verificationcode,
      })
    }    
 
  }
})
